﻿using BCCommon;
using BCDto.TMS.Contraband.ContrabandCategory;
using BCService.TMS.Contraband.ContrabandCategory;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.Contraband
{
    /// <summary>
    /// 违禁品分类
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class ContrabandCategoryController : ManagementBaseController
    {
        #region var
        private readonly IContrabandCategoryService contrabandCategoryService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public ContrabandCategoryController(IContrabandCategoryService contrabandCategoryService)
        {
            this.contrabandCategoryService = contrabandCategoryService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新违禁品分类
        /// </summary>
        /// <param name="requestDto">违禁品分类数据模型</param>
        /// <response code="201">添加新违禁品分类</response>
        /// <returns></returns>
        [Log("添加新违禁品分类纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(ContrabandCategoryDto), 201)]
        public IActionResult Post([FromBody] ContrabandCategoryRequestDto requestDto)
        {
            var result = this.contrabandCategoryService.Add(requestDto, this.Admin);
            return Ok(result);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改违禁品分类
        /// </summary>
        /// <param name="contrabandCategoryId">违禁品分类Id</param>
        /// <param name="requestDto">违禁品分类数据模型</param>
        /// <response code="200">修改违禁品分类</response>
        /// <returns></returns>
        [Log("修改违禁品分类纪录")]
        [HttpPut("{contraband_category_id}")]
        [ProducesResponseType(typeof(ContrabandCategoryDto), 200)]
        public IActionResult Put([FromRoute(Name = "contraband_category_id")] int contrabandCategoryId,
            [FromBody] ContrabandCategoryRequestDto requestDto)
        {
            var result = this.contrabandCategoryService.Update(requestDto, contrabandCategoryId, this.Admin);
            return this.Ok(result);
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除违禁品分类
        /// </summary>
        /// <param name="contrabandCategoryId">违禁品分类ID</param>
        /// <response code="204">删除违禁品分类</response>
        /// <returns></returns>
        [Log("删除违禁品分类纪录")]
        [HttpDelete("{contraband_category_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "contraband_category_id")] int contrabandCategoryId)
        {
            this.contrabandCategoryService.Delete(this.Admin, contrabandCategoryId);
            return NoContent();
        }
        #endregion

        #region Query 查询违禁品分类
        /// <summary>
        /// 获取违禁品分类
        /// </summary>
        /// <param name="contrabandCategory">违禁品分类</param>
        /// <param name="createStartDate">创建开始日期</param>
        /// <param name="createEndDate">创建结束日期</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取违禁品分类</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<ContrabandCategoryDto>), 200)]
        public IActionResult Query([FromQuery(Name = "contraband_category")]string contrabandCategory,
            [FromQuery(Name = "create_start_date")] DateTime? createStartDate,
            [FromQuery(Name = "create_end_date")] DateTime? createEndDate,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var result = this.contrabandCategoryService.Query(this.Admin, contrabandCategory, createStartDate, createEndDate, pageIndex, pageSize);
            return this.Ok(result);
        }
        #endregion

        #region List 查询违禁品分类列表
        /// <summary>
        /// 查询违禁品分类列表
        /// </summary>
        /// <param name="contrabandCategory">违禁品分类</param>
        /// <response code="200">查询违禁品分类列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<ContrabandCategoryDto>), 200)]
        public IActionResult List([FromQuery(Name = "contraband_category")] string contrabandCategory)
        {
            var result = this.contrabandCategoryService.GetList(this.Admin, contrabandCategory);
            return this.Ok(result);
        }
        #endregion
    }
}
